package com.zlzxm.shoesmarket.view.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zlzxm.shoesmarket.R;

import org.jetbrains.annotations.NotNull;

/**
 * CREATE BY zlzxm ON 4/26/21
 */
public class ADCalculateSize extends BaseQuickAdapter<ADCalculateSize.EntityGoodsSizeTag, BaseViewHolder> {


    private int selectPosition = -1;

    public void setSelectPosition(int position){

        if(selectPosition == position){

            return;
        }


        if(selectPosition!=-1){

            ADCalculateSize.EntityGoodsSizeTag old = getData().get(selectPosition);
            ADCalculateSize.EntityGoodsSizeTag newEntity = getData().get(position);

            old.setSelect(false);

            newEntity.setSelect(true);

            notifyDataSetChanged();

            selectPosition = position;

        }else {

            ADCalculateSize.EntityGoodsSizeTag newEntity = getData().get(position);


            newEntity.setSelect(true);

            notifyDataSetChanged();

            selectPosition = position;


        }



    }


    public ADCalculateSize() {
        super(R.layout.item_calculate_size);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, EntityGoodsSizeTag entity) {

        holder.itemView.setSelected(entity.isSelect);

        holder.setText(R.id.tvSize,entity.getSize());


    }

    public static class EntityGoodsSizeTag {

        private boolean isSelect;

        private String id;

        private String size;

        public EntityGoodsSizeTag( String id, String size) {
            this.id = id;
            this.size = size;
        }

        boolean isSelect() {
            return isSelect;
        }

        void setSelect(boolean select) {
            isSelect = select;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getSize() {
            return size;
        }

        public void setSize(String size) {
            this.size = size;
        }
    }
}
